package cn.kbblog.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicInteger;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;

/**
 * 测试生成订单唯一的id
 * @author yang.kb@topcheer.com
 * @date 2017年10月10日 下午12:26:39
 */
public class SerialGenerator {

	private final AtomicRangeInteger atomicRangeInteger = new AtomicRangeInteger(0, Integer.MAX_VALUE);

	public long getSerialId(){
		final long currentTimeMillis = System.currentTimeMillis();
		return (long) (currentTimeMillis << 32 | atomicRangeInteger.incrAndGet());
	}
	
	public static void main(String[] args) throws Exception {
		 SerialGenerator generator = new SerialGenerator();
	
		for (int i = 0; i < 10000; i++) {
			long serialId = generator.getSerialId();
			System.out.println("serialId:"+serialId);
		}
		
	}
}
